package com.xianyun.smartpicturebackend.exception;

/** 异常处理工具类
 * @author xianYun
 * @version 1.0
 **/
public class ThrowUtils {
    /**
     * 条件成立则抛出异常对象
     * @param condition 条件
     * @param runtimeException 异常对象
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立抛出自定义异常对象
     * @param condition 条件
     * @param errorCode 错误码
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 指定异常对象的错误码，和错误信息
     * @param condition 条件
     * @param errorCode 错误码
     * @param message 错误信息
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }

}
